import asyncio
import time


async def crawl_page(url):
    print('crawling {}'.format(url))
    sleep_time = int(url.split('_')[-1])
    await asyncio.sleep(sleep_time)
    print('OK {}'.format(url))


def timelog(func):
    def wrapper(*args, **kwargs):
        start = time.time()
        func(*args, **kwargs)
        end = time.time()
        print('wall time:{}'.format(end - start))

    return wrapper


@timelog
def test_timelog():
    for i in range(10000000):
        i += i
    print('finish')


# async def main(urls):
#     for url in urls:
#         await crawl_page(url)

async def main(urls):
  tasks = [asyncio.create_task(crawl_page(url)) for url in urls]
  await asyncio.gather(*tasks)

if __name__ == '__main__':
    start = time.time()
    asyncio.run(main(['url_1', 'url_2', 'url_3', 'url_3', 'url_4']))
    end = time.time()
    print('wall time:{}'.format(end - start))
